const Koa = require('koa');
const cors = require('@koa/cors');
const bodyParser = require('koa-bodyparser');
const logger = require('koa-logger');

const { book_router } = require('./router/book_router');
const { movie_router } = require('./router/movie_router');

const PORT = process.env.PORT || 3001;

const app = new Koa();

app
  .use(cors())
  .use(logger({
    format: ':date[iso] :method :url :status :response-time ms - :res[content-length]',
  }))
  .use(bodyParser())
  .use(book_router.allowedMethods())
  .use(book_router.routes())
  .use(movie_router.allowedMethods())
  .use(movie_router.routes());

app.listen(PORT, () => console.log(`http://localhost:${PORT}`));